﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tomahawk.Runtime;
using Tomahawk.Runtime.Logic;
using Microsoft.Xna.Framework;
using Tomahawk.Runtime.Rendering.Materials;

namespace Initialization.GameStates
{
    public class LightActor : XActor
    {
        float time = 0.0f;

        public LightActor()
        {
            Engine.Instance.EffectEnvironment.light0.position = new Vector4(-50, 60, 0, 0);
            Engine.Instance.EffectEnvironment.light0.specular = new Vector4(1, 1, 1, 0);
            Engine.Instance.EffectEnvironment.light0.ambient = new Vector4(0.1f, 0.1f, 0.1f, 0);
            UpdateRequired = true;
        }

        protected override void OnUpdate(float elapsedTime)
        {
            time += elapsedTime;
            Engine.Instance.EffectEnvironment.light0.position.Z = 200.0f * (float) Math.Sin(time);
            base.OnUpdate(elapsedTime);
        }
    }

    public class TeapotActor : XActor
    {
        public TeapotActor()
        {
            UpdateRequired = true;
        }

        protected override void OnUpdate(float elapsedTime)
        {
            Quaternion delta = Quaternion.CreateFromAxisAngle(Vector3.Forward, elapsedTime);
            this.SetRotation(this.SceneComponent.SceneNode.Rotation * delta);
            base.OnUpdate(elapsedTime);
        }
    }

    class BasicGameState : GameState
    {
        protected override void OnLoad()
        {
            //TeapotActor teapot1 = (TeapotActor)XWorld.Instance.CreateObject(typeof(TeapotActor), "Teapot1", @"Examples.Shaders.Content\teapot1actor.xml");
            //TeapotActor teapot2 = (TeapotActor)XWorld.Instance.CreateObject(typeof(TeapotActor), "Teapot2", @"Examples.Shaders.Content\teapot2actor.xml");
            //TeapotActor teapot3 = (TeapotActor)XWorld.Instance.CreateObject(typeof(TeapotActor), "Teapot3", @"Examples.Shaders.Content\teapot3actor.xml");
            LightActor light = (LightActor)XWorld.Instance.CreateObject(typeof(LightActor));
            TeapotActor teapot4 = (TeapotActor)XWorld.Instance.CreateObject(typeof(TeapotActor), "Teapot4", @"Examples.Shaders.Content\teapot4actor.xml");
            TeapotActor teapot5 = (TeapotActor)XWorld.Instance.CreateObject(typeof(TeapotActor), "Teapot5", @"Examples.Shaders.Content\teapot5actor.xml");
            TeapotActor teapot6 = (TeapotActor)XWorld.Instance.CreateObject(typeof(TeapotActor), "Teapot6", @"Examples.Shaders.Content\teapot6actor.xml");
            //TeapotActor teapot7 = (TeapotActor)XWorld.Instance.CreateObject(typeof(TeapotActor), "Teapot7", @"Examples.Shaders.Content\teapot7actor.xml");
            //TeapotActor teapot8 = (TeapotActor)XWorld.Instance.CreateObject(typeof(TeapotActor), "Teapot8", @"Examples.Shaders.Content\teapot8actor.xml");
            //TeapotActor teapot9 = (TeapotActor)XWorld.Instance.CreateObject(typeof(TeapotActor), "Teapot9", @"Examples.Shaders.Content\teapot9actor.xml");
            Engine.Instance.ResourceManager.LoadPendantResources(this.ContentManager);
        }

        protected override void OnUnload()
        {
        }

        protected override void OnInitialize()
        {
            // Locate the camera in a convenient way
            Tomahawk.Runtime.Rendering.Camera camera = Engine.Instance.CameraManager.ActiveCamera;
            camera.LookAt(
                new Vector3(-300, 60, 0),
                new Vector3(0, 0, 0),
                Vector3.UnitY);
        }

        protected override void OnDestroy()
        {
        }
    }
}
